home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 7
/
BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso
/
Files
/
DA
/
P
/
PTable.cpt
/
DeskAcc.Pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1987-11-17
|
10KB
|
375 lines
PROGRAM DeskAccExample;
USES MacIntf;
CONST accEvent = 64;
accRun = 65;
accCursor = 66;
accMenu = 67;
accUndo = 68;
accCut = 70;
accCopy = 71;
accPaste = 72;
accClear = 73;
maxatom = 105;
bboxw = 64;
bboxh = 98;
lboxw = 17;
lboxh = 17;
startptx = 10;
startpty = 10;
bboxstx = 327;
bboxsty = 34;
maxbox = 18;
maxrow = 9;
TYPE tablesize = 0..maxatom;
BitPtr = ^BitMap;
BitHandle = ^BitPtr;
picArray = ARRAY[1..maxatom] OF Rect;
DAGlobals = record
lilpic :picArray;
tablebits : BitHandle;
whichelement : tablesize;
end;
DAGlobalsP = ^DAGlobals;
DAGlobalsH = ^DAGlobalsP;
PROCEDURE FigureRect(Device: DCtlEntry);
TYPE boxrange = 1..maxbox;
rowrange = 1..maxrow;
boxes = SET OF boxrange;
tabletype = ARRAY[1..maxrow] OF boxes;
VAR index : rowrange;
table : tabletype;
tempset : boxes;
element : tablesize;
PROCEDURE onerow(VAR element : tablesize;
row : rowrange;
whichones : boxes);
VAR count : boxrange;
top,left,bottom,right : integer;
DAGlobalsHndl : DAGlobalsH;
BEGIN
top := startpty+(row-1)*lboxh - (row-1);
bottom := top + lboxh;
FOR count := 1 to maxbox DO
IF count IN whichones THEN
BEGIN
left := startptx + (count-1)*lboxw - (count-1);
right := left + lboxw;
HLock(Device.DCtlStorage);
DAGlobalsHndl := DAGlobalsH(Device.DCtlStorage);
WITH DAGlobalsHndl^^ DO
SetRect(lilpic[element],left,top,right,bottom);
HUnlock(Device.DCtlStorage);
element := element + 1;
END;
END;
BEGIN
element := 1;
table[1] := [1,18];
table[2] := [1,2,13,14,15,16,17,18];
table[3] := table[2];
table[4] := [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18];
table[5] := table[4];
table[6] := [1,2,3];
FOR index := 1 to 6 DO
onerow(element,index,table[index]);
element := 72;
tempset := [4,5,6,7,8,9,10,11,12,13,14,15,16,17,18];
onerow(element,6,tempset);
tempset := [1,2,3];
element := 87;
onerow(element,7,tempset);
tempset := [4,5];
element := 104;
onerow(element,7,tempset);
tempset := [5,6,7,8,9,10,11,12,13,14,15,16,17,18];
element := 58;
onerow(element,8,tempset);
element := 90;
onerow(element,9,tempset);
END;
PROCEDURE WhichBox(where: Point;
Device : DCtlEntry);
VAR index : tablesize;
DAGlobalsHndl : DAGlobalsH;
BEGIN
GlobaltoLocal(where);
HLock(Device.DCtlStorage);
DAGlobalsHndl := DAGlobalsH(Device.DCtlStorage);
With DAGlobalsHndl^^ DO
BEGIN
FOR index := 1 to maxatom DO
IF PtInRect(where, lilpic[index])
THEN BEGIN
whichelement := index;
InsetRect(lilpic[whichelement],1,1);
InvertRect(lilpic[whichelement]);
InsetRect(lilpic[whichelement],-1,-1);
EXIT;
END;
whichelement := 0;
END;
HUnlock(Device.DCtlStorage);
END;
PROCEDURE DrawBigpic(Device: DCtlEntry);
VAR bigrect,arect : Rect;
index, first, ResourceID, hoffset : integer;
savergn, bigrgn, theclip : RgnHandle;
DAGlobalsHndl : DAGlobalsH;
thepic : picHandle;
BEGIN
SetRect(bigrect,bboxstx,bboxsty,bboxstx + bboxw,bboxsty + bboxh);
InsetRect(bigrect,1,1);
EraseRect(bigrect);
InsetRect(bigrect,-1,-1);
FrameRect(bigrect);
Hlock(Device.DCtlStorage);
DAGlobalsHndl := DAGlobalsH(Device.DCtlStorage);
WITH DAGlobalsHndl^^ DO
FOR index := 0 TO 5 DO
BEGIN
first := index*20 + 1;
IF (whichelement-first < 20) AND (whichelement >= first) THEN
BEGIN
ResourceID := $BFE0 + 32*(-Device.DCtlRefNum) + 3;
thepic := GetPicture(ResourceID + index);
arect := thepic^^.picFrame;
OffsetRect(arect,bboxstx-arect.left - 3,bboxsty-arect.top - 4);
hoffset := -((whichelement-first)*bboxw - (whichelement-first));
OffsetRect(arect,hoffset,0);
savergn := NewRgn;
bigrgn := NewRgn;
theclip := NewRgn;
GetClip(theclip);
GetClip(savergn);
RectRgn(bigrgn,bigrect);
SectRgn(bigrgn,savergn,theclip);
SetClip(theclip);
DrawPicture(thepic,arect);
SetClip(savergn);
DisposeRgn(savergn);
DisposeRgn(theclip);
DisposeRgn(bigrgn);
ReleaseResource(Handle(thepic));
END;
END;
HUnlock(Device.DCtlStorage);
END;
PROCEDURE DrawTable(Device:DCtlEntry);
VAR
ResourceID : integer;
theWind : WindowPtr;
srcbits, destbits : BitMap;
srcrect, destrect : Rect;
DAGlobalsHndl : DAGlobalsH;
BEGIN
theWind := WindowPtr(Device.DCtlWindow);
SetPort(theWind);
DAGlobalsHndl := DAGlobalsH(Device.DCtlStorage);
WITH DAGlobalsHndl^^ DO
BEGIN
srcrect := tablebits^^.bounds;
srcbits := tablebits^^;
END;
destrect := srcrect;
offsetrect(destrect,startptx-destrect.left-2,startpty-destrect.top-2);
destbits := theWind^.portBits;
Copybits(srcbits,destbits,srcrect,destrect,1,NIL);
DrawBigpic(Device);
END;
PROCEDURE DrawPitch(Device:DCtlEntry);
VAR pitchdl : PicHandle;
ResourceID : Integer;
theWind : WindowPtr;
BEGIN
theWind := WindowPtr(Device.DCtlWindow);
SetPort(theWind);
ResourceID := $BFE0 + 32*(-Device.DctlRefNum) + 9;
pitchdl := GetPicture(ResourceID);
HLock(Handle(pitchdl));
DrawPicture(pitchdl, pitchdl^^.picFrame);
FlushEvents(mDownMask,0);
WHILE NOT Button DO;
FlushEvents(mDownMask,0);
EraseRect(pitchdl^^.picFrame);
HUnlock(Handle(pitchdl));
ReleaseResource(Handle(pitchdl));
END;
PROCEDURE UpdateDA(var Device: DCtlEntry);
begin
BeginUpdate(WindowPtr(Device.DCtlWindow));
DrawTable(Device);
EndUpdate(WindowPtr(Device.DCtlWindow))
end; { of UpdateDA }
(* ***** The Open, Ctl, and Close procedures for a Desk Accessory ***** *)
PROCEDURE Open(VAR Device: DCtlEntry;
VAR Block: ParamBlockRec);
VAR ResourceID: Integer;
tempint : longint;
TmpPtr: Ptr;
WPeek: WindowPeek;
DAGlobalsHndl : DAGlobalsH;
tempbits : BitHandle;
BEGIN
{ Check to see if this is the first time to be Opened. }
if Device.DctlWindow = nil then begin
{ Compute resource ID of this Desk Accessory. Remember Font/DA Mover can
change them on you. That's why we use resource numbers which are OWNED
by a particular DRVR resource for Menus, Windows, etc.}
ResourceID := $BFE0 + 32 * (-Device.DCtlRefNum);
{ Allocate the "global" storage for the Desk Accessory }
Device.DctlStorage := NewHandle(SIZEOF(DAGlobals));
{ Create a hole in the heap. It is good practice to keep Window records
off of the bottom of the Application Heap. }
TmpPtr := NewPtr($1000);
Device.DctlWindow := Pointer(GetNewWindow(ResourceID,nil,Pointer(-1)));
WPeek := WindowPeek(Device.DCtlWindow);
WPeek^.WindowKind := Device.DCtlRefNum;
{ Make it the current port to make appropriate calls define the port }
SetPort(GrafPtr(Device.DCtlWindow));
SetOrigin(0,0);
FlushEvents(EveryEvent,0);
{ add calls for textsize, font, etc. }
{ Deallocate our temporary pointer }
DisposPtr(TmpPtr);
{ Perform other activities associated with opening the Desk Accessory }
ResourceID := $BFE0 + 32*(-Device.DCtlRefNum) + 1;
tempbits := BitHandle(GetResource('BITS',ResourceID));
tempbits^^.baseAddr := @tempbits^^.bounds;
tempint := Longint(tempbits^^.baseAddr);
tempint := tempint + 8;
tempbits^^.baseAddr := Pointer(tempint);
HLock(Device.Dctlstorage);
DAGlobalsHndl := DAGlobalsH(Device.DctlStorage);
With DAGlobalsHndl^^ do
begin
whichelement := 0;
tablebits := tempbits;
end;
HUnlock(Device.DctlStorage);
FigureRect(Device);
DrawPitch(Device);
DrawTable(Device);
end;
END; (* of Open *)
PROCEDURE Ctl(VAR Device: DCtlEntry;
VAR Block: ParamBlockRec);
(* The Ctl procedure is the main entry point for System Calls.
The ParamBlckRec parameter tells us what is going on. Use the infromation
in here to decide on an action to take.
*)
VAR Trick: Record
case integer of
0: (CSParam: array[0..1] of Integer);
1: (EventPtr: ^EventRecord)
end;
DAGlobalsHndl : DAGLobalsH;
BEGIN
{ Set the current grafport to ours }
SetPort(GrafPtr(Device.DCtlWindow));
{ Assuming the DA's "globals" are going to be used, lets lock them down. }
HLock(Device.DCtlStorage);
DAGlobalsHndl := DAGlobalsH(Device.DCtlStorage);
WITH DAGlobalsHndl^^ DO
{ Find out what happened. }
case Block.csCode of
accEvent: begin
Trick.CSParam[0] := Block.CSParam[0];
Trick.CSParam[1] := Block.CSParam[1];
case Trick.EventPtr^.what of
mouseDown:BEGIN
WhichBox(Trick.eventPtr^.where,Device);
WHILE StillDown DO;
FlushEvents(MUpMask,0);
IF whichelement <> 0 THEN
BEGIN
InsetRect(lilpic[whichelement],1,1);
InvertRect(lilpic[whichelement]);
InsetRect(lilpic[whichelement],-1,-1);
END;
DrawBigpic(Device);
END;
keyDown: ;
keyUp: ;
updateEvt: UpdateDA(Device);
activateEvt: ;
end;
end;
accRun: ;
accCursor: ;
accMenu: ;
accUndo: ;
accCut: ;
accCopy: ;
accPaste: ;
accClear: ;
end;
HUnLock(Device.DCtlStorage);
END; (* of Ctl *)
PROCEDURE Close(VAR Device: DCtlEntry;
VAR Block: ParamBlockRec);
(* Well this is it! The Desk Manager has called you to tell you this is the
end. You are not allowed to do anything but to remove your windows,
menu, etc. and reclaim any storage.
*)
BEGIN
with Device do
begin
DisposeWindow(WindowPtr(Device.DCtlWindow));
dctlWindow := nil;
(* Reclaim the private storage area that we allocated for ourselves. *)
disposHandle(Handle(DCtlStorage));
end;
END; (* of Close *)
BEGIN
(* No main program allowed *)
END.